<template>
    <div class="hg-tab-wrapper">
        <ul :class="direction" ref="box">
            <li class="item" v-for="(item, index) in list" @click="toggle($event, item.value)" :key="index"><i :class="`fa fa-${item.icon}`"></i> {{item.label}}</li>
        </ul>
    </div>
</template>

<script>
import _ from 'lodash'
import {siblings} from '../../scripts/until'

export default {
    name: 'hgTab',
    props:{
        list:{
            default: [
                {
                    icon: '',
                    label: '1',
                    value: '1'
                }
            ]
        },
        direction: {
            default: "level"
            // vertical
        }
    },
    data: function() {	
        return {}
    },
    methods: {
        toggle($event, item) {
            $event.currentTarget.classList.add('active')
            let sibling = siblings($event.currentTarget)
            _.forEach(sibling, item=>{
                item.classList.remove('active')
            })
            this.$emit('change', item)
        }
    },
    mounted(){
        this.$refs.box.querySelector(".item").classList.add('active');
        this.$emit('change', this.list[0].value)
    }
}
</script>

<style lang="scss">
.hg-tab-wrapper{
    height: 45px;
    .level{
        margin: 0 auto;
        width: 100%;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-around;
        border-top: none;
        .item{
            border-bottom: 2px solid #DFE4ED;
        }
        .active{
            color: #2275c7;
            border-bottom: 2px solid #2275c7;
        }
    }
    .item{
        width: 100%;
        line-height: 25px;
        height: 45px;
        text-align: center;
        padding: 10px;
        font-size: 16px;
        color: #5A5E66;
        cursor: pointer;
        transition: .4s ease-in-out        
    }
    .vertical{
        width: 128px;
        // height: 200px;
        margin: 0 auto;
        display: flex;
        flex-direction: column;
        .item{
            background: #F1F1F1;
            margin-bottom: 10px;
            padding: 10px;
            &:hover{
                background: #2873a6;
                color: #fff;
            }
        }
        .active{
            background: #2873a6;
            color: #fff;
        }
    }
}
</style>